<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});
/**
 * 数据可视化
 */
Route::group(['prefix' => 'admin', 'namespace' => 'Api'],function (){
    //会员性别统计
    Route::get('sex_total','EchartController@sex_total')->name('sex_total');
    //省份人数统计
    Route::get('province_total','EchartController@province_total')->name('province_total');
    Route::post('bind','EchartController@bind')->name('bind');
});

Route::group(['namespace'=>'Wechat'],function (){
    Route::any('/wechat', 'WechatController@serve');
});

/***
 *小米商城 vue
 */
Route::group(['namespace'=>'Api'],function (){
    Route::get('/','HomeController@index');
    Route::any('authenticate','AuthenticateController@authenticate');

    Route::group(['prefix' => 'product'], function () {
        //商品分类
        Route::get('category', 'ProductController@category');

        Route::get('product_list', 'ProductController@product_list');//商品列表
        Route::get('show/{id}', 'ProductController@show');//商品展示
        Route::get('search', 'ProductController@search');//搜索
    });

    Route::group(['middleware' => ['jwt.auth']],function (){
        Route::group(['prefix'=>'cart'],function (){
           Route::get('/','CartController@index');
           Route::patch('/','CartController@change_num');
            Route::post('/', 'CartController@store');//添加商品到购物车
            Route::delete('/', 'CartController@destroy');//删除购物车商品
        });

        //订单
        Route::group(['prefix' => 'order'], function () {
            Route::get('check_out', 'OrderController@check_out');//去结算

            Route::post('/', 'OrderController@store');//生成订单
            Route::get('show_pay', 'OrderController@show_pay');//去付款

            Route::get('{id}', 'OrderController@index');//全部订单
            Route::get('show/{id}', 'OrderController@show');//订单详情

            Route::delete('{id}', 'OrderController@destroy');//删除订单
        });

        //地址
        Route::group(['prefix' => 'address'], function () {
            Route::get('address_list','AddressController@address_list');
            Route::post('address_create','AddressController@address_create');
            //改变默认地址
            Route::patch('default_address', 'AddressController@default_address');
            //管理地址
            Route::get('manage', 'AddressController@manage');

        });

    });
});
